package com.hmall.web;

import com.hmall.Service.SearchService;
import com.hmall.common.dto.PageDTO;
import com.hmall.pojo.ItemDoc;
import com.hmall.pojo.RequestParams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("search")
@Slf4j
public class SearchController {

    @Autowired
    private SearchService searchService;

    @PostMapping("filters")
    public Map<String,List<String>> getFilters(@RequestBody RequestParams params){
        return searchService.getFilters(params);
    }

    /**
     * 分页
     * @param params
     * @return
     */
    @PostMapping("list")
    public PageDTO PageItem(@RequestBody RequestParams params){
        PageDTO pageDTO = searchService.PageItem(params);
        return pageDTO;

    }


    /**
     * 自动补全
     * @param key
     * @return
     */
    @GetMapping("suggestion")
    public List<String> Itemsuggestion(@RequestParam("key") String key){
        List<String> itemsuggestion = searchService.Itemsuggestion(key);
        return itemsuggestion;
    }
}
